import {useState,useEffect} from 'react';
import Taro from '@tarojs/taro';
import {RadioGroup,View,Radio,Textarea} from '@tarojs/components';
import {getGlobalData,Request} from '../../util';
import Styles from './index.module.less';
import NavBar from '../../component/navbar';

export default function index(props){

    const domain = getGlobalData('domain');
    const navBarHeight = Taro.getStorageSync('navBarHeight');
    const openid = Taro.getStorageSync('openid');
    const [comment,setComment] = useState(null);
    const [type,setType] = useState(null);

    const handleChange = (e) => {
        setType(e.detail.value);
    }

    const handleContentInput = (e) =>
    {
        setComment(e.detail.value);
    }

    const handleSbumit = () => {
        if(type == null){
            Taro.showModal({
                content:"请选择反馈类型",
                showCancel:false,
            })
        }else if(comment == null){
            Taro.showModal({
                content:"请填写问题或建议",
                showCancel:false,
            })
        }else{
            Request(domain+"/client/feedback/submitFeedback",{openid:openid, type:type,comment:comment}).then((res)=>{
                if(res.data.code == 200){
                    Taro.showModal({
                        content:"提交成功，工作不足我们深表歉意，你的建议我们会有专人处理和改进，感谢你的支持！",
                        showCancel:false,
                        success:function(e){
                            if(e.confirm){
                                Taro.switchTab({
                                    url:"/pages/center/index"
                                })
                            }
                        }
                    })
                }

            })
        }

       
    }

    return (
        <>
            <NavBar title="意见反馈" backTo="prev"/>
            <view class={Styles.type} style={{marginTop: navBarHeight+10}}>
                <view class={Styles.tip} >
                    1.请选择反馈问题的类型
                </view>
                <RadioGroup class={Styles.radio_group} onChange={handleChange}>
                    <View class={Styles.radio_wrap}>
                            <text>预约问题</text>
                            <Radio color="#D1A8A8" value={1}></Radio>
                    </View>

                    <View class={Styles.radio_wrap}>
                            <text>服务问题</text>
                            <Radio  color="#D1A8A8" value={2}></Radio>
                    </View>
             
                    <View class={Styles.radio_wrap}>
                            <text>收费问题</text>
                            <Radio color="#D1A8A8" value={3}></Radio>
                    </View>
                </RadioGroup>
            </view>

            <view class={Styles.comment}>
                <view class={Styles.tip}>2.请填写问题或建议</view>
                <Textarea onInput={handleContentInput}></Textarea>
            </view>

            <view class={Styles.submit}>
                <view class={Styles.btn} onClick={handleSbumit}>提交</view>
            </view>
            

        </>
    )
}